//
//  MIDIlandingController.m
//  迷笛
//
//  Created by . on 2018/10/8.
//  Copyright © 2018年 🍃🌺🌺🍃. All rights reserved.
//

#import "MIDIlandingController.h"
#import "MIDIverifyController.h"
#import "MIDImodel.h"
//#import "RegulariPhone.h"
#import "RegisObj_C.h"
@interface MIDIlandingController ()<UITextFieldDelegate>
{
    NSString *KEy;
}
@property(nonatomic,strong)UIButton * cancel;
@property(nonatomic,strong)UILabel * landing;//登陆文字
@property(nonatomic,strong)UILabel * number;//+86
@property(nonatomic,strong)UILabel * xx;//线
@property(nonatomic,strong)UITextField * input;
@property(nonatomic,strong)UILabel * xxtwo;//线
@property(nonatomic,strong)UIButton * landingbtn;
@property(nonatomic,strong)UIButton * weibo;
@property(nonatomic,strong)UIButton * qq;
@property(nonatomic,strong)UIButton * weixin;
@property(nonatomic,strong)UIButton * deal;
@property(nonatomic,strong)NSString * midisendSms;

@end

@implementation MIDIlandingController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.translucent = NO;//Bar的模糊效果，默认为YES
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;

    self.view.backgroundColor =[UIColor colorWithHexString:@"#1B212F"];
    

    [self UIin];
}
-(void)Verification
{
    
    NSString * sendSms = @"sendSms";
    _midisendSms = [NSString stringWithFormat:@"%@%@",MIDIApiRoot,sendSms];
    NSDictionary * parameter =@{@"mobile":_input.text};
    [EdHttp post:_midisendSms params:parameter progress:^(id uploadProgress)
    {
        
    }
         success:^(id responseObject)
    {
        
        NSLog(@"登陆接口%@",responseObject);
        NSDictionary * dic = responseObject[@"data"];
        KEy = [dic objectForKey:@"key"];
        NSLog(@"KeyKeyKeyKey--%@",KEy);
    
    }
         failure:^(NSError *error)
    {
        
    }];
}

//视图将要出现时（导航颜色字体颜色）
- (void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = YES;
    
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:@"#1B212F"];
    
     [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#FFFFFF"]}];
    //    去掉导航黑线
    UIImage *img = [UIImage imageNamed:@""];
    [self.navigationController.navigationBar setBackgroundImage:img  forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
}
-(void)UIin
{
    [self.view addSubview:self.cancel];
    [self.cancel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(kDevice_Is_iPhoneX?HeighX(70):HeightScale(30));
        make.left.mas_offset(WidthScale(16));
        make.width.mas_offset(WidthScale(21));
        make.height.mas_offset(HeightScale(21));
    }];
    
    
    [self.view addSubview:self.landing];
    [self.landing mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.cancel.mas_bottom).mas_offset(WidthScale(20));
        make.left.mas_offset(WidthScale(36));
        make.width.mas_offset(WidthScale(200));
        make.height.mas_offset(HeighX(23));
    }];
    [self.view addSubview:self.number];
    [self.number mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.landing.mas_bottom).offset(WidthScale(70));
        make.left.equalTo(self.landing);
        [self.number setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    }];
    [self.view addSubview:self.xx];
    [self.xx mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.number);
        make.left.equalTo(self.number.mas_right).offset(WidthScale(10));
        make.width.mas_offset(WidthScale(1));
        make.height.mas_offset(kDevice_Is_iPhoneX?HeighX(23):HeightScale(23));
    }];
    [self.view addSubview:self.input];
    [self.input mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.number);
        make.left.equalTo(self.xx.mas_right).offset(WidthScale(10));
        make.width.mas_offset(WidthScale(200));
        make.height.mas_offset(kDevice_Is_iPhoneX?HeighX(40):HeightScale(40));
    }];
    [self.view addSubview:self.xxtwo];
    [self.xxtwo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.xx.mas_bottom).offset(WidthScale(20));
        make.left.equalTo(self.number);
        make.width.mas_offset(WidthScale(300));
        make.height.mas_offset(HeightScale(0.6));
    }];
    [self.view addSubview:self.landingbtn];
    [self.landingbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.xxtwo).offset(WidthScale(200));
        make.centerX.equalTo(self.view);
        make.width.mas_offset(WidthScale(305));
        make.height.mas_offset(kDevice_Is_iPhoneX?HeighX(50):HeightScale(50));
    }];
    [self.view addSubview:self.qq];
    [self.qq mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_offset(kDevice_Is_iPhoneX?HeighX(-98):HeightScale(-60));
        make.centerX.equalTo(self.view);
        make.width.mas_offset(WidthScale(30));
        make.height.mas_offset(HeighX(30));
    }];
    [self.view addSubview:self.weibo];
    [self.weibo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.qq);
        make.left.mas_offset(WidthScale(64));
        make.width.mas_offset(WidthScale(30));
        make.height.mas_offset(HeighX(30));
    }];
    [self.view addSubview:self.weixin];
    [self.weixin mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.qq);
        make.right.mas_offset(WidthScale(-64));
        make.width.mas_offset(WidthScale(30));
        make.height.mas_offset(HeighX(30));
    }];
    
    [self.view addSubview:self.deal];
    [self.deal mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_offset(kDevice_Is_iPhoneX?HeighX(-48):HeightScale(-10));
        make.centerX.equalTo(self.view);
    [self.deal setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    }];
}
//设置手机号码长度方法
- (void)textFieldDidChange:(UITextField *)textField
{
    UITextRange *selectedRange = textField.markedTextRange;
    UITextPosition *position = [textField positionFromPosition:selectedRange.start offset:0];
    if (!position)
    {
        if (_input.text.length >= 11 )
        {
            _input.text = [_input.text substringToIndex:11];
        }
    }
}
-(UIButton *)cancel
{
    if (!_cancel)
    {
        _cancel =[[UIButton alloc]init];
        [_cancel setBackgroundImage:[UIImage imageNamed:@"chacha"] forState:0];
        [_cancel addTarget:self action:@selector(cancel:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _cancel;
}
-(void)cancel:(UIButton * )sender
{
    [self dismissViewControllerAnimated:YES completion:nil];
}
-(UILabel *)landing
{
    if (!_landing)
    {
        _landing =[[UILabel alloc]init];
        _landing.text = @"快捷登录注册";
        _landing.font =[UIFont systemFontOfSize:WidthScale(25)];
        _landing.textColor = [UIColor colorWithHexString:@"#FFFFFF"];
    }
    return _landing;
}
-(UILabel *)number
{
    if (!_number)
    {
        _number =[[UILabel alloc]init];
        _number.text = @"+86";
        _number.textColor = [UIColor colorWithHexString:@"#FFFFFF"];
        _number.font =[UIFont systemFontOfSize:WidthScale(20)];
    }
    return _number;
}
-(UILabel *)xx
{
    if (!_xx)
    {
        _xx = [[UILabel alloc]init];
        _xx.backgroundColor =[UIColor colorWithHexString:@"#FFFFFF"];
    }
    return _xx;
}
-(UITextField *)input
{
    if (!_input)
    {
        _input =[[UITextField alloc]init];
        _input.borderStyle = UITextBorderStyleNone;
        _input.placeholder = @"请输入手机号";
        _input.textColor =[UIColor whiteColor];
        [_input setValue:[UIColor colorWithHexString:@"#999999"] forKeyPath:@"_placeholderLabel.textColor"];
        [_input addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
    }
    return _input;
}
-(UILabel *)xxtwo
{
    if (!_xxtwo)
    {
        _xxtwo =[[UILabel alloc]init];
        _xxtwo.backgroundColor =[UIColor colorWithHexString:@"#9D9EA0"];
    }
    return _xxtwo;
}
-(UIButton *)landingbtn
{
    if (!_landingbtn)
    {
        _landingbtn = [[UIButton alloc]init];
        _landingbtn.userInteractionEnabled = NO;
        [_landingbtn setBackgroundImage:[UIImage imageNamed:@"xiayibu-hui"] forState:0];
        [_landingbtn addTarget:self action:@selector(Btn:) forControlEvents:UIControlEventTouchUpInside];
        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(change:) name:UITextFieldTextDidChangeNotification object:self.input];
    }
    return _landingbtn;
}

-(void)change:(NSNotification *)notification
{
    if (self.input.text.length == 11) {
        self.landingbtn.userInteractionEnabled = YES;
        [_landingbtn setBackgroundImage:[UIImage imageNamed:@"xiayibu"] forState:0];        //        NSLog(@"内容大于0可以点击");
    }else
    {
        self.landingbtn.userInteractionEnabled = NO;
        [_landingbtn setBackgroundImage:[UIImage imageNamed:@"xiayibu-hui"] forState:0];//        NSLog(@"内容为空不可点击");
    }
}
-(void)Btn:(UIButton * )sender
{
    if (self.input.text.length == 11 && [RegisObj_C valiMobile:_input.text])
    {
      

        [self Verification];
       
        MIDIverifyController * land =[[MIDIverifyController alloc]init];
        land.str = self.input.text; //对需要传递的变量进行复制
        land.Key = KEy;
        NSLog(@"输入手机号中的key%@",land.Key);
      
            [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
            [SVProgressHUD showWithStatus:@"加载中"];
            [SVProgressHUD dismissWithDelay:2.0];
   
         
            [self presentViewController:land animated:YES completion:nil];
        
        
//        [self.navigationController pushViewController:land animated:YES];
//        [self presentViewController:land animated:YES completion:nil];

        
        NSLog(@"内容大于0可以点击");
    }else
    {
        [SVProgressHUD setMinimumDismissTimeInterval:0.5];
        [SVProgressHUD showErrorWithStatus:@"请输入正确手机号"];
        NSLog(@"内容为空不可点击");
    }
}



-(UIButton *)weibo
{
    if (!_weibo)
    {
        _weibo =[[UIButton alloc]init];
        [_weibo setBackgroundImage:[UIImage imageNamed:@"weibo"] forState:0];
        
    }
    return _weibo;
}
-(UIButton *)qq
{
    if (!_qq)
    {
        _qq =[[UIButton alloc]init];
        [_qq setBackgroundImage:[UIImage imageNamed:@"形状 3"] forState:0];
    }
    return _qq;
}
-(UIButton *)weixin
{
    if (!_weixin)
    {
        _weixin =[[UIButton alloc]init];
        [_weixin setBackgroundImage:[UIImage imageNamed:@"weixin"] forState:0];
    }
    return _weixin;
}
-(UIButton *)deal
{
    if (!_deal)
    {
        _deal =[[UIButton alloc]init];
        [_deal setTitle:@"登录/注册即视为同意用户服务协议" forState:0];
        [_deal setTitleColor:[UIColor colorWithHexString:@"#999999"] forState:0];
        _deal.titleLabel.font =[UIFont systemFontOfSize:WidthScale(12)];
    }
    return _deal;
}
@end
